package com.udaos.modules.statistics.controllers;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.By;
import org.nutz.mvc.annotation.Filters;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import com.udaos.common.filter.PrivateFilter;
import com.udaos.common.page.DataTableColumn;
import com.udaos.common.page.DataTableOrder;
import com.udaos.modules.statistics.services.UdWxpayTransService;
import com.udaos.modules.wx.services.WxConfigService;

@IocBean
@At("/platform/statistics/wxtrans")
@Filters({ @By(type = PrivateFilter.class)})
public class UdWxpayTransController {
	
	@Inject
	private UdWxpayTransService udWxpayTransService;
	@Inject
	private WxConfigService wxConfigService;
	
	@At("")
	@Ok("beetl:/platform/statistics/wxtrans/index.html")
	@RequiresAuthentication
	public void index() {
		
	}
	
	@At
	@Ok("json:full")
	@RequiresAuthentication
	public Object data(@Param("name") String name,@Param("length") int length, @Param("start") int start, @Param("draw") int draw, @Param("::order") List<DataTableOrder> order, @Param("::columns") List<DataTableColumn> columns) {
		Cnd cnd = Cnd.NEW();
		if (!Strings.isBlank(name))
			cnd.and("name", "like", "%" + name + "%");
		return udWxpayTransService.data(length, start, draw, order, columns, cnd, null);
	}
	
	@At
	@Ok("json") 
	@RequiresAuthentication
	public Object getWxConfig(String id){
		if(!Strings.isBlank(id)){
			return wxConfigService.fetch(Cnd.where("appid", "=", id)).getAppname();
		}else{
			return "";
		}
	}

}
